import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent, STData } from '@delon/abc';
import { SFSchema } from '@delon/form';
import { ColumnType, SPage } from '@shared/components/table-page/table-page.component';
import { NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { PeopleDetailComponent } from '../people-detail/people-detail.component';

@Component({
  selector: 'app-person-list',
  templateUrl: './person-list.component.html',
  styleUrls:['./index.less']
})
export class PersonListComponent implements OnInit {
  @ViewChild('st', { static: false }) st: STComponent;
  isVisible = false;
  config: SPage = {
    columns: [
      /*{
        index: 'id',
        title: '多选',
        type: ColumnType.checkbox,
      },*/
      {
        index: 'infoName',
        title: '姓名',
        filter: {
          placeholder: '请输入姓名',
          type: 'string'
        }
      },
      {
        index: 'infoSex',
        title: '性别',
        filter: {
          placeholder: '请选择性别',
          type: 'select',
          hideSearch: true,
          items: [
            { label: '男', value: '1' },
            { label: '女', value: '2' }
          ]
        }
      },
      {
        index: 'houseAdress',
        title: '房屋地址',
        filter: {
          placeholder: '请输入房屋地址',
          type: 'string'
        }
      },
      {
          index: 'roomNumber',
        title: '房号',
        filter: {
          placeholder: '请输房号',
          type: 'string'
        }
      },
      {
        index: 'infoMobile',
        title: '手机号码',
        /*filter: {
          placeholder: '请输入手机号',
          type: 'string'
        }*/
      },
      {
        index: 'infoIdcardNumber',
        title: '证件号码',
        filter: {
          placeholder: '请输入证件号码',
          type: 'string'
        }
      },
      /*{
        index: 'infoNativeAddress',
        title: '户籍所在地',
        filter: {
          placeholder: '请输入户籍所在地',
          type: 'string'
        }
      },*/
      {
        index: 'status',
        title: '人员类型',
        filter: {
          placeholder: '请选择人员类型',
          type: 'select',
          defatuts: '1',
          items:[
            {label:'现住人员',value: '1'},
            {label:'退租人员',value: '0'},
          ]
        }
      },
      {
        index: 'roomInTime',
        title: '入住时间',

        filter: {
          placeholder: '请输入入住时间',
          type: 'date',
        }
      },
      {
        index: 'roomOutTime',
        title: '退租时间',
        filter: {
          placeholder: '',
          type: 'date',
        }
      }
    ],
    showCheckBox: true,
    editBtn:[
      {title:'查看详情'}
    ],
    reqUrl: this.api.peopleInfo.page.url
  }
  statistics = {
    APPCOUNT: 0,
    CARDCOUNT: 0,
    PEOPLECOUNT: 0
  }
  constructor(private http: _HttpClient, private modal: NzModalService, private api: ApiService) { }

  ngOnInit() {
    this.getStatistics();
  }

  // 根据状态检索不需要被全选的数据
  dataProcess() {
    return this.config.data.map((i: STData, index: number) => {
      return i;
    });
  }
  // 操作区
  operate(e): void {
    if (e.title === '查看详情') {
      this.previewDital(e.data);
    }
  }
  // 选择数据
  selectChange(e) {
    console.log(e);

  }

  /**
   * 查看详情
   * @param _param 人员详情
   */
  previewDital(_param): void {
    this.modal.create({
      nzTitle: '人员详情',
      nzWidth: 1000,
      nzContent: PeopleDetailComponent,
      nzComponentParams: {
        _param
      },
      nzFooter: null
    })
  }
  getStatistics(): void {
    this.http.request<any>(this.api.peopleInfo.cardStatistics.method, this.api.peopleInfo.cardStatistics.url).subscribe(res => {
      if(res.status === '200') {
        this.statistics = res.data;
      }
    })
  }
}
